import React from 'react';

const Countdown = ({ targetDate }) => {
    const [time, setTime] = React.useState({ minutes: 0, seconds: 0 });

    React.useEffect(() => {
        const interval = setInterval(() => {
            const now = new Date();
            const t = new Date(targetDate) - now;

            if (t > 0) {
                // 对于分钟可以不是60分钟
                const minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));
                const seconds = Math.floor((t % (1000 * 60)) / 1000);

                setTime({ minutes, seconds });
            } else {
                clearInterval(interval);
            }
        }, 1000);

        return () => clearInterval(interval);
    }, [targetDate]);

    return (
        <div className="a" >  
            <div>{time.minutes}分 {time.seconds}秒 后开始</div>
        </div>
    );
};

export default Countdown;